home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / WIN / UltraDev / UltraDev_Trial.exe / Disk1 / data1.cab / Configuration_En / Commands / DesignNotesMultiFile.js < prev    next >
Encoding:
JavaScript  |  2000-12-11  |  8.1 KB  |  330 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS  *****************
  4.  
  5. var helpDoc = MM.HELP_cmdDesignNotes;
  6.  
  7. var KEY_STATUS = "status";
  8. var KEY_NOTES  = "notes";
  9. var KEY_OPEN   = "showOnOpen";
  10. var PAIR_SEP   = " = ";
  11. var DEFAULT_STATUS = 0;
  12.  
  13. var T = ''; //TabControl object
  14. var DATA;
  15. var FILE_PTR = 0;
  16.  
  17. var FILE_IS_WRITEABLE;
  18.  
  19. //*************** Pg1 Class *****************
  20.  
  21. function Pg1(theTabLabel) {
  22.   this.tabLabel    = theTabLabel;
  23.  
  24.   this.listObj     = new ListControl("statusMenu");
  25.   this.notesObj    = findObject("notesField");
  26.   this.openObj     = findObject("openChbx");
  27. }
  28.  
  29.  
  30. //***** methods *****
  31.  
  32. Pg1.prototype.getTabLabel = Pg1_getTabLabel; //required
  33. Pg1.prototype.canLoad = Pg1_canLoad;
  34. Pg1.prototype.load = Pg1_load;
  35. Pg1.prototype.update = Pg1_update;
  36. Pg1.prototype.unload = Pg1_unload;
  37.  
  38.  
  39. function Pg1_getTabLabel() {
  40.   return this.tabLabel;
  41. }
  42.  
  43.  
  44. //Called to check if a page can be loaded
  45. //
  46. function Pg1_canLoad() {
  47.   return true;
  48. }
  49.  
  50.  
  51. //Called when the layer for this page is displayed.
  52. // Use this call to initialize controls.
  53.  
  54. function Pg1_load() {
  55.   var i;
  56.  
  57.   with (this) {
  58.     listObj.setAll(STATUS_ITEMS); //load select menu
  59.  
  60.     //get status
  61.     temp = stripSpaces(DATA.get(KEY_STATUS));
  62.     if (!temp) listObj.setIndex(DEFAULT_STATUS);
  63.     else {
  64.       for (i=0; i<listObj.getLen(); i++) { //look for status in menu
  65.         if (listObj.get(i) == temp) {
  66.           listObj.setIndex(i);
  67.           break;
  68.       } }
  69.       if (i == listObj.getLen()) listObj.append(temp); //if nonexistent, add it
  70.     }
  71.  
  72.     //get notes
  73.     temp = DATA.get(KEY_NOTES);
  74.     notesObj.value = temp || "";
  75.  
  76.     //get open flag
  77.     temp = DATA.get(KEY_OPEN);
  78.     if (temp != null) openObj.checked = (temp.toString().toLowerCase() == "true");
  79.   }
  80. }
  81.  
  82.  
  83. //Called when another page is about to be shown, or finish() is called on
  84. // the tabControl.  Use this call to perform any finishing tasks.
  85.  
  86. function Pg1_unload() {
  87.   return true;
  88. }
  89.  
  90.  
  91. //Called when one of the page controls calls the tabControl update function.
  92. // Use this call to respond to user input.
  93. function Pg1_update(theItemName) {
  94.  
  95.   with (this) {
  96.       if (theItemName == "insertDate") {
  97.         var theDate = getSimpleDate() + ": \n";
  98.         notesObj.value = theDate + notesObj.value;
  99.         DATA.set(KEY_NOTES,notesObj.value || null); //save notes
  100.  
  101.       } else if (theItemName == "statusMenu") {
  102.         DATA.set(KEY_STATUS,listObj.get() || null); //save status
  103.  
  104.       } else if (theItemName == "notesField") {
  105.         DATA.set(KEY_NOTES,notesObj.value || null); //save notes
  106.  
  107.       } else if (theItemName == "openChbx") {
  108.         DATA.set(KEY_OPEN,openObj.checked || null); //save open flag
  109.       }
  110.   }
  111. }
  112.  
  113.  
  114.  
  115.  
  116. //***************** Pg2 Class ******************
  117.  
  118. function Pg2(theTabLabel) {
  119.   this.tabLabel    = theTabLabel;
  120.  
  121.   this.listObj     = new ListControl("allItems");
  122.   this.nameObj     = findObject("itemName");
  123.   this.valueObj    = findObject("itemValue");
  124.   this.keys        = new Array();
  125. }
  126.  
  127.  
  128. //***** methods *****
  129.  
  130. Pg2.prototype.getTabLabel = Pg2_getTabLabel;
  131. Pg2.prototype.canLoad = Pg2_canLoad;
  132. Pg2.prototype.load = Pg2_load;
  133. Pg2.prototype.update = Pg2_update;
  134. Pg2.prototype.unload = Pg2_unload;
  135. Pg2.prototype.drawList = Pg2_drawList;
  136. Pg2.prototype.drawSelection = Pg2_drawSelection;
  137.  
  138.  
  139.  
  140. function Pg2_getTabLabel() {
  141.   return this.tabLabel;
  142. }
  143.  
  144.  
  145.  
  146. //Called to check if a page can be loaded
  147. //
  148. function Pg2_canLoad() {
  149.   return true;
  150. }
  151.  
  152.  
  153.  
  154. //Called when the layer for this page is displayed.
  155. // Use this call to initialize controls.
  156. //
  157. function Pg2_load() {
  158.   with (this) {
  159.     drawList();
  160.     listObj.setIndex(0); //select first item
  161.     drawSelection()
  162.   }
  163. }
  164.  
  165.  
  166.  
  167. //Called when another page is about to be shown, or finish() is called on
  168. // the tabControl.  Use this call to perform any finishing tasks.
  169. function Pg2_unload() {
  170.   return true;
  171. }
  172.  
  173.  
  174.  
  175. //Called when one of the page controls calls the tabControl update function.
  176. // Use this call to respond to user input.
  177. function Pg2_update(theItemName) {
  178.   var i, temp, temp2;
  179.  
  180.   if (theItemName == "allItems") with (this) {
  181.     drawSelection();
  182.  
  183.   } else {
  184.  
  185.     if (theItemName == "addItem") with (this) {
  186.       listObj.append();
  187.       valueObj.value = "";
  188.       nameObj.value  = "";
  189.       nameObj.focus();
  190.       nameObj.select();
  191.   
  192.     } else if (theItemName == "delItem") with (this) {
  193.       DATA.del(listObj.getIndex());
  194.       listObj.del();
  195.       drawSelection();
  196.   
  197.     } else if (theItemName == "itemName" || theItemName == "itemValue") with (this) {
  198.       temp = nameObj.value;
  199.  
  200.       if (temp.toLowerCase() == "design notes credits") {
  201.         valueObj.value = unescape("%42%72%6F%75%67%68%74 %74%6F %79%6F%75 %62%79...\n%48%65%69%64%69, %4B%65%6E,"+
  202.                                   " %53%74%65%70%68%61%6E%69%65, %61%6E%64 %4A%61%6B%65!\n%59%65%65-%68%61%77!");
  203.       }
  204.  
  205.       temp2 = (valueObj.value);
  206.       if (temp) { //if valid name
  207.         temp = stripSpaces(makeValidKey(temp));
  208.         if (temp) { //if valid name
  209.           if (listObj.get()) { //if selection is not blank (not new item)
  210.             var oldName = DATA.getName(listObj.getIndex()); //get prior name
  211.             if (temp != oldName) DATA.changeName(oldName,temp); //if name changed, update it
  212.           }
  213.           DATA.set(temp,temp2 || null);
  214.           drawList();
  215.         } else {
  216.           alert(MSG_InvalidName);
  217.         }     
  218.       }
  219.     }
  220.   }
  221. }
  222.  
  223.  
  224. //Called when the layer for this page is displayed.
  225. // Use this call to initialize controls.
  226. //
  227. function Pg2_drawList() {
  228.   var i, allItems;
  229.  
  230.   with (this) {
  231.     listObj.setAll(DATA.getAll());       //clear out the old list
  232.     if (listObj.getLen() > 0) {
  233.       drawSelection();                      //display stuff in fields
  234.     }
  235.   }
  236. }
  237.  
  238.  
  239. function Pg2_drawSelection() {
  240.   var name, value;
  241.  
  242.   with (this) {
  243.     name = DATA.getName(listObj.getIndex()); //get the name for the current selection
  244.     name = name || ""; //make blank if null
  245.     nameObj.value = name;
  246.     value = DATA.get(name);
  247.     value = value || ""; //make blank if null
  248.     valueObj.value = value;
  249.   }
  250. }
  251.  
  252.  
  253. //***************** End of Pg2 Class ******************
  254.  
  255. //******************* API **********************
  256.  
  257. function commandButtons(){
  258.   var btns;
  259.  
  260.   btns = new Array(BTN_OK,     "okClicked()", BTN_Cancel, "cancelClicked()", BTN_Help, "displayHelp()");
  261.   return btns
  262. }
  263.  
  264. //***************** LOCAL FUNCTIONS  ******************
  265.  
  266. function initializeUI() {
  267.   var result;
  268.  
  269.   DATA = new NameValuePair();
  270.   T = new TabControl('Tab');
  271.   //Add tab pages.   (Pass the layer name, and the page object)
  272.   T.addPage('mainLayer', new Pg1(LABEL_BasicInfo));
  273.   T.addPage('allLayer', new Pg2(LABEL_AllInfo));
  274.   //Initialize and display the tabs.  (Could pass the name of a page to start on)
  275.   T.start();
  276. }
  277.  
  278.  
  279.  
  280. function okClicked() {
  281.   T.finish();
  282.   writeMetafiles();
  283.   window.close();
  284.  
  285.   //update design notes columns in local file list in site window
  286.   if (MMNotes.UpdateSite == true)
  287.     site.refresh("local");
  288. }
  289.  
  290. function cancelClicked() {
  291.   window.close();
  292. }
  293.  
  294.  
  295. function writeMetafiles() {
  296.   var i, names;
  297.  
  298.   site.setFocus("local");
  299.  
  300.   //iterate through each file/folder in the selection
  301.   //and set the access permissions for each
  302.   var localFileList = site.getSelection();
  303.   var numSelected = localFileList.length;
  304.   for (file=0; file<numSelected; file++) {
  305.       //for each file write out new note
  306.       FILE_PTR = MMNotes.open(localFileList[file]);
  307.       names = DATA.getNames();
  308.       for (i=0; i<names.length; i++)  {  //with each local, non-null key
  309.         MMNotes.set(FILE_PTR,names[i],DATA.get(names[i]));  //set it in the file
  310.       }
  311.       MMNotes.close(FILE_PTR);
  312.   }
  313. }
  314.  
  315.  
  316.  
  317. function makeValidKey(theStr) {
  318.   theStr = theStr.replace(/(\")/g,""); //disallow "
  319.   theStr = theStr.replace(/(\')/g,""); //disallow '
  320.   return theStr;
  321. }
  322.  
  323. function getSimpleDate() {
  324.   var today = new Date();
  325.   var dateStr = today.toLocaleString();
  326.   dateStr = dateStr.replace(/\S+\s+(\S+\s+\S+\s+\S+)[^\x00]*/,"$1"); //get 2nd-4th words of date
  327.   return dateStr;
  328. }
  329.  
  330.